home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / awksrc.zip / DFA.H < prev    next >
C/C++ Source or Header  |  1992-07-28  |  23KB  |  540 lines

  1. /* dfa.h - declarations for GNU deterministic regexp compiler
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.                       Written June, 1988 by Mike Haertel
  4.  
  5.                NO WARRANTY
  6.  
  7.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  8. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  9. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  10. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  11. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  12. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  13. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  14. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  15. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  16. CORRECTION.
  17.  
  18.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  19. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  20. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  21. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  22. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  23. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  24. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  25. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  26. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  27. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  28.  
  29.         GENERAL PUBLIC LICENSE TO COPY
  30.  
  31.   1. You may copy and distribute verbatim copies of this source file
  32. as you receive it, in any medium, provided that you conspicuously and
  33. appropriately publish on each copy a valid copyright notice "Copyright
  34.  (C) 1988 Free Software Foundation, Inc."; and include following the
  35. copyright notice a verbatim copy of the above disclaimer of warranty
  36. and of this License.  You may charge a distribution fee for the
  37. physical act of transferring a copy.
  38.  
  39.   2. You may modify your copy or copies of this source file or
  40. any portion of it, and copy and distribute such modifications under
  41. the terms of Paragraph 1 above, provided that you also do the following:
  42.  
  43.     a) cause the modified files to carry prominent notices stating
  44.     that you changed the files and the date of any change; and
  45.  
  46.     b) cause the whole of any work that you distribute or publish,
  47.     that in whole or in part contains or is a derivative of this
  48.     program or any part thereof, to be licensed at no charge to all
  49.     third parties on terms identical to those contained in this
  50.     License Agreement (except that you may choose to grant more extensive
  51.     warranty protection to some or all third parties, at your option).
  52.  
  53.     c) You may charge a distribution fee for the physical act of
  54.     transferring a copy, and you may at your option offer warranty
  55.     protection in exchange for a fee.
  56.  
  57. Mere aggregation of another unrelated program with this program (or its
  58. derivative) on a volume of a storage or distribution medium does not bring
  59. the other program under the scope of these terms.
  60.  
  61.   3. You may copy and distribute this program or any portion of it in
  62. compiled, executable or object code form under the terms of Paragraphs
  63. 1 and 2 above provided that you do the following:
  64.  
  65.     a) accompany it with the complete corresponding machine-readable
  66.     source code, which must be distributed under the terms of
  67.     Paragraphs 1 and 2 above; or,
  68.  
  69.     b) accompany it with a written offer, valid for at least three
  70.     years, to give any third party free (except for a nominal
  71.     shipping charge) a complete machine-readable copy of the
  72.     corresponding source code, to be distributed under the terms of
  73.     Paragraphs 1 and 2 above; or,
  74.  
  75.     c) accompany it with the information you received as to where the
  76.     corresponding source code may be obtained.  (This alternative is
  77.     allowed only for noncommercial distribution and only if you
  78.     received the program in object code or executable form alone.)
  79.  
  80. For an executable file, complete source code means all the source code for
  81. all modules it contains; but, as a special exception, it need not include
  82. source code for modules which are standard libraries that accompany the
  83. operating system on which the executable file runs.
  84.  
  85.   4. You may not copy, sublicense, distribute or transfer this program
  86. except as expressly provided under this License Agreement.  Any attempt
  87. otherwise to copy, sublicense, distribute or transfer this program is void and
  88. your rights to use the program under this License agreement shall be
  89. automatically terminated.  However, parties who have received computer
  90. software programs from you with this License Agreement will not have
  91. their licenses terminated so long as such parties remain in full compliance.
  92.  
  93.   5. If you wish to incorporate parts of this program into other free
  94. programs whose distribution conditions are different, write to the Free
  95. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  96. worked out a simple rule that can be stated here, but we will often permit
  97. this.  We will be guided by the two goals of preserving the free status of
  98. all derivatives our free software and of promoting the sharing and reuse of
  99. software.
  100.  
  101.  
  102. In other words, you are welcome to use, share and improve this program.
  103. You are forbidden to forbid anyone else to use, share and improve
  104. what you give them.   Help stamp out software-hoarding!  */
  105.  
  106. #ifdef __STDC__
  107.  
  108. #ifdef SOMEDAY
  109. #define ISALNUM(c) isalnum(c)
  110. #define ISALPHA(c) isalpha(c)
  111. #define ISUPPER(c) isupper(c)
  112. #else
  113. #define ISALNUM(c) (isascii(c) && isalnum(c))
  114. #define ISALPHA(c) (isascii(c) && isalpha(c))
  115. #define ISUPPER(c) (isascii(c) && isupper(c))
  116. #endif
  117.  
  118. #else /* ! __STDC__ */
  119.  
  120. #define const
  121.  
  122. #define ISALNUM(c) (isascii(c) && isalnum(c))
  123. #define ISALPHA(c) (isascii(c) && isalpha(c))
  124. #define ISUPPER(c) (isascii(c) && isupper(c))
  125.  
  126. #endif /* ! __STDC__ */
  127.  
  128. /* 1 means plain parentheses serve as grouping, and backslash
  129.      parentheses are needed for literal searching.
  130.    0 means backslash-parentheses are grouping, and plain parentheses
  131.      are for literal searching.  */
  132. #define RE_NO_BK_PARENS 1L
  133.  
  134. /* 1 means plain | serves as the "or"-operator, and \| is a literal.
  135.    0 means \| serves as the "or"-operator, and | is a literal.  */
  136. #define RE_NO_BK_VBAR (1L << 1)
  137.  
  138. /* 0 means plain + or ? serves as an operator, and \+, \? are literals.
  139.    1 means \+, \? are operators and plain +, ? are literals.  */
  140. #define RE_BK_PLUS_QM (1L << 2)
  141.  
  142. /* 1 means | binds tighter than ^ or $.
  143.    0 means the contrary.  */
  144. #define RE_TIGHT_VBAR (1L << 3)
  145.  
  146. /* 1 means treat \n as an _OR operator
  147.    0 means treat it as a normal character */
  148. #define RE_NEWLINE_OR (1L << 4)
  149.  
  150. /* 0 means that a special characters (such as *, ^, and $) always have
  151.      their special meaning regardless of the surrounding context.
  152.    1 means that special characters may act as normal characters in some
  153.      contexts.  Specifically, this applies to:
  154.     ^ - only special at the beginning, or after ( or |
  155.     $ - only special at the end, or before ) or |
  156.     *, +, ? - only special when not after the beginning, (, or | */
  157. #define RE_CONTEXT_INDEP_OPS (1L << 5)
  158.  
  159. /* 1 means that \ in a character class escapes the next character (typically
  160.    a hyphen.  It also is overloaded to mean that hyphen at the end of the range
  161.    is allowable and means that the hyphen is to be taken literally. */
  162. #define    RE_AWK_CLASS_HACK (1L << 6)
  163.  
  164. /* Now define combinations of bits for the standard possibilities.  */
  165. #ifdef notdef
  166. #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS)
  167. #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
  168. #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  169. #define RE_SYNTAX_EMACS 0
  170. #endif
  171.  
  172. /* The NULL pointer. */
  173. #ifndef NULL
  174. #define NULL 0
  175. #endif
  176.  
  177. /* Number of bits in an unsigned char. */
  178. #define CHARBITS 8
  179.  
  180. /* First integer value that is greater than any character code. */
  181. #define _NOTCHAR (1 << CHARBITS)
  182.  
  183. /* INTBITS need not be exact, just a lower bound. */
  184. #define INTBITS (CHARBITS * sizeof (int))
  185.  
  186. /* Number of ints required to hold a bit for every character. */
  187. #define _CHARSET_INTS ((_NOTCHAR + INTBITS - 1) / INTBITS)
  188.  
  189. /* Sets of unsigned characters are stored as bit vectors in arrays of ints. */
  190. typedef int _charset[_CHARSET_INTS];
  191.  
  192. /* The regexp is parsed into an array of tokens in postfix form.  Some tokens
  193.    are operators and others are terminal symbols.  Most (but not all) of these
  194.    codes are returned by the lexical analyzer. */
  195. #ifdef __STDC__
  196.  
  197. typedef enum
  198. {
  199.   _END = -1,            /* _END is a terminal symbol that matches the
  200.                    end of input; any value of _END or less in
  201.                    the parse tree is such a symbol.  Accepting
  202.                    states of the DFA are those that would have
  203.                    a transition on _END. */
  204.  
  205.   /* Ordinary character values are terminal symbols that match themselves. */
  206.  
  207.   _EMPTY = _NOTCHAR,        /* _EMPTY is a terminal symbol that matches
  208.                    the empty string. */
  209.  
  210.   _BACKREF,            /* _BACKREF is generated by \<digit>; it
  211.                    it not completely handled.  If the scanner
  212.                    detects a transition on backref, it returns
  213.                    a kind of "semi-success" indicating that
  214.                    the match will have to be verified with
  215.                    a backtracking matcher. */
  216.  
  217.   _BEGLINE,            /* _BEGLINE is a terminal symbol that matches
  218.                    the empty string if it is at the beginning
  219.                    of a line. */
  220.  
  221.   _ALLBEGLINE,            /* _ALLBEGLINE is a terminal symbol that
  222.                    matches the empty string if it is at the
  223.                    beginning of a line; _ALLBEGLINE applies
  224.                    to the entire regexp and can only occur
  225.                    as the first token thereof.  _ALLBEGLINE
  226.                    never appears in the parse tree; a _BEGLINE
  227.                    is prepended with _CAT to the entire
  228.                    regexp instead. */
  229.  
  230.   _ENDLINE,            /* _ENDLINE is a terminal symbol that matches
  231.                    the empty string if it is at the end of
  232.                    a line. */
  233.  
  234.   _ALLENDLINE,            /* _ALLENDLINE is to _ENDLINE as _ALLBEGLINE
  235.                    is to _BEGLINE. */
  236.  
  237.   _BEGWORD,            /* _BEGWORD is a terminal symbol that matches
  238.                    the empty string if it is at the beginning
  239.                    of a word. */
  240.  
  241.   _ENDWORD,            /* _ENDWORD is a terminal symbol that matches
  242.                    the empty string if it is at the end of
  243.                    a word. */
  244.  
  245.   _LIMWORD,            /* _LIMWORD is a terminal symbol that matches
  246.                    the empty string if it is at the beginning
  247.                    or the end of a word. */
  248.  
  249.   _NOTLIMWORD,            /* _NOTLIMWORD is a terminal symbol that
  250.                    matches the empty string if it is not at
  251.                    the beginning or end of a word. */
  252.  
  253.   _QMARK,            /* _QMARK is an operator of one argument that
  254.                    matches zero or one occurences of its
  255.                    argument. */
  256.  
  257.   _STAR,            /* _STAR is an operator of one argument that
  258.                    matches the Kleene closure (zero or more
  259.                    occurrences) of its argument. */
  260.  
  261.   _PLUS,            /* _PLUS is an operator of one argument that
  262.                    matches the positive closure (one or more
  263.                    occurrences) of its argument. */
  264.  
  265.   _CAT,                /* _CAT is an operator of two arguments that
  266.                    matches the concatenation of its
  267.                    arguments.  _CAT is never returned by the
  268.                    lexical analyzer. */
  269.  
  270.   _OR,                /* _OR is an operator of two arguments that
  271.                    matches either of its arguments. */
  272.  
  273.   _LPAREN,            /* _LPAREN never appears in the parse tree,
  274.                    it is only a lexeme. */
  275.  
  276.   _RPAREN,            /* _RPAREN never appears in the parse tree. */
  277.  
  278.   _SET                /* _SET and (and any value greater) is a
  279.                    terminal symbol that matches any of a
  280.                    class of characters. */
  281. } _token;
  282.  
  283. #else /* ! __STDC__ */
  284.  
  285. typedef short _token;
  286.  
  287. #define _END -1
  288. #define _EMPTY _NOTCHAR
  289. #define _BACKREF (_EMPTY + 1)
  290. #define _BEGLINE (_EMPTY + 2)
  291. #define _ALLBEGLINE (_EMPTY + 3)
  292. #define _ENDLINE (_EMPTY + 4)
  293. #define _ALLENDLINE (_EMPTY + 5)
  294. #define _BEGWORD (_EMPTY + 6)
  295. #define _ENDWORD (_EMPTY + 7)
  296. #define _LIMWORD (_EMPTY + 8)
  297. #define _NOTLIMWORD (_EMPTY + 9)
  298. #define _QMARK (_EMPTY + 10)
  299. #define _STAR (_EMPTY + 11)
  300. #define _PLUS (_EMPTY + 12)
  301. #define _CAT (_EMPTY + 13)
  302. #define _OR (_EMPTY + 14)
  303. #define _LPAREN (_EMPTY + 15)
  304. #define _RPAREN (_EMPTY + 16)
  305. #define _SET (_EMPTY + 17)
  306.  
  307. #endif /* ! __STDC__ */
  308.  
  309. /* Sets are stored in an array in the compiled regexp; the index of the
  310.    array corresponding to a given set token is given by _SET_INDEX(t). */
  311. #define _SET_INDEX(t) ((t) - _SET)
  312.  
  313. /* Sometimes characters can only be matched depending on the surrounding
  314.    context.  Such context decisions depend on what the previous character
  315.    was, and the value of the current (lookahead) character.  Context
  316.    dependent constraints are encoded as 8 bit integers.  Each bit that
  317.    is set indicates that the constraint succeeds in the corresponding
  318.    context.
  319.  
  320.    bit 7 - previous and current are newlines
  321.    bit 6 - previous was newline, current isn't
  322.    bit 5 - previous wasn't newline, current is
  323.    bit 4 - neither previous nor current is a newline
  324.    bit 3 - previous and current are word-constituents
  325.    bit 2 - previous was word-constituent, current isn't
  326.    bit 1 - previous wasn't word-constituent, current is
  327.    bit 0 - neither previous nor current is word-constituent
  328.  
  329.    Word-constituent characters are those that satisfy isalnum().
  330.  
  331.    The macro _SUCCEEDS_IN_CONTEXT determines whether a a given constraint
  332.    succeeds in a particular context.  Prevn is true if the previous character
  333.    was a newline, currn is true if the lookahead character is a newline.
  334.    Prevl and currl similarly depend upon whether the previous and current
  335.    characters are word-constituent letters. */
  336. #define _MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn) \
  337.   ((constraint) & (1 << (((prevn) ? 2 : 0) + ((currn) ? 1 : 0) + 4)))
  338. #define _MATCHES_LETTER_CONTEXT(constraint, prevl, currl) \
  339.   ((constraint) & (1 << (((prevl) ? 2 : 0) + ((currl) ? 1 : 0))))
  340. #define _SUCCEEDS_IN_CONTEXT(constraint, prevn, currn, prevl, currl) \
  341.   (_MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn)             \
  342.    && _MATCHES_LETTER_CONTEXT(constraint, prevl, currl))
  343.  
  344. /* The following macros give information about what a constraint depends on. */
  345. #define _PREV_NEWLINE_DEPENDENT(constraint) \
  346.   (((constraint) & 0xc0) >> 2 != ((constraint) & 0x30))
  347. #define _PREV_LETTER_DEPENDENT(constraint) \
  348.   (((constraint) & 0x0c) >> 2 != ((constraint) & 0x03))
  349.  
  350. /* Tokens that match the empty string subject to some constraint actually
  351.    work by applying that constraint to determine what may follow them,
  352.    taking into account what has gone before.  The following values are
  353.    the constraints corresponding to the special tokens previously defined. */
  354. #define _NO_CONSTRAINT 0xff
  355. #define _BEGLINE_CONSTRAINT 0xcf
  356. #define _ENDLINE_CONSTRAINT 0xaf
  357. #define _BEGWORD_CONSTRAINT 0xf2
  358. #define _ENDWORD_CONSTRAINT 0xf4
  359. #define _LIMWORD_CONSTRAINT 0xf6
  360. #define _NOTLIMWORD_CONSTRAINT 0xf9
  361.  
  362. /* States of the recognizer correspond to sets of positions in the parse
  363.    tree, together with the constraints under which they may be matched.
  364.    So a position is encoded as an index into the parse tree together with
  365.    a constraint. */
  366. typedef struct
  367. {
  368.   unsigned index;        /* Index into the parse array. */
  369.   unsigned constraint;        /* Constraint for matching this position. */
  370. } _position;
  371.  
  372. /* Sets of positions are stored as arrays. */
  373. typedef struct
  374. {
  375.   _position *elems;        /* Elements of this position set. */
  376.   int nelem;            /* Number of elements in this set. */
  377. } _position_set;
  378.  
  379. /* A state of the regexp consists of a set of positions, some flags,
  380.    and the token value of the lowest-numbered position of the state that
  381.    contains an _END token. */
  382. typedef struct
  383. {
  384.   int hash;            /* Hash of the positions of this state. */
  385.   _position_set elems;        /* Positions this state could match. */
  386.   char newline;            /* True if previous state matched newline. */
  387.   char letter;            /* True if previous state matched a letter. */
  388.   char backref;            /* True if this state matches a \<digit>. */
  389.   unsigned char constraint;    /* Constraint for this state to accept. */
  390.   int first_end;        /* Token value of the first _END in elems. */
  391. } _dfa_state;
  392.  
  393. /* If an r.e. is at most MUST_MAX characters long, we look for a string which
  394.    must appear in it; whatever's found is dropped into the struct reg. */
  395.  
  396. #define MUST_MAX    50
  397.  
  398. /* A compiled regular expression. */
  399. struct regexp
  400. {
  401.   /* Stuff built by the scanner. */
  402.   _charset *charsets;        /* Array of character sets for _SET tokens. */
  403.   int cindex;            /* Index for adding new charsets. */
  404.   int calloc;            /* Number of charsets currently allocated. */
  405.  
  406.   /* Stuff built by the parser. */
  407.   _token *tokens;        /* Postfix parse array. */
  408.   int tindex;            /* Index for adding new tokens. */
  409.   int talloc;            /* Number of tokens currently allocated. */
  410.   int depth;            /* Depth required of an evaluation stack
  411.                    used for depth-first traversal of the
  412.                    parse tree. */
  413.   int nleaves;            /* Number of leaves on the parse tree. */
  414.   int nregexps;            /* Count of parallel regexps being built
  415.                    with regparse(). */
  416.  
  417.   /* Stuff owned by the state builder. */
  418.   _dfa_state *states;        /* States of the regexp. */
  419.   int sindex;            /* Index for adding new states. */
  420.   int salloc;            /* Number of states currently allocated. */
  421.  
  422.   /* Stuff built by the structure analyzer. */
  423.   _position_set *follows;    /* Array of follow sets, indexed by position
  424.                    index.  The follow of a position is the set
  425.                    of positions containing characters that
  426.                    could conceivably follow a character
  427.                    matching the given position in a string
  428.                    matching the regexp.  Allocated to the
  429.                    maximum possible position index. */
  430.   int searchflag;        /* True if we are supposed to build a searching
  431.                    as opposed to an exact matcher.  A searching
  432.                    matcher finds the first and shortest string
  433.                    matching a regexp anywhere in the buffer,
  434.                    whereas an exact matcher finds the longest
  435.                    string matching, but anchored to the
  436.                    beginning of the buffer. */
  437.  
  438.   /* Stuff owned by the executor. */
  439.   int tralloc;            /* Number of transition tables that have
  440.                    slots so far. */
  441.   int trcount;            /* Number of transition tables that have
  442.                    actually been built. */
  443.   int **trans;            /* Transition tables for states that can
  444.                    never accept.  If the transitions for a
  445.                    state have not yet been computed, or the
  446.                    state could possibly accept, its entry in
  447.                    this table is NULL. */
  448.   int **realtrans;        /* Trans always points to realtrans + 1; this
  449.                    is so trans[-1] can contain NULL. */
  450.   int **fails;            /* Transition tables after failing to accept
  451.                    on a state that potentially could do so. */
  452.   int *success;            /* Table of acceptance conditions used in
  453.                    regexecute and computed in build_state. */
  454.   int *newlines;        /* Transitions on newlines.  The entry for a
  455.                    newline in any transition table is always
  456.                    -1 so we can count lines without wasting
  457.                    too many cycles.  The transition for a
  458.                    newline is stored separately and handled
  459.                    as a special case.  Newline is also used
  460.                    as a sentinel at the end of the buffer. */
  461.   char must[MUST_MAX];
  462.   int mustn;
  463. };
  464.  
  465. /* Some macros for user access to regexp internals. */
  466.  
  467. /* ACCEPTING returns true if s could possibly be an accepting state of r. */
  468. #define ACCEPTING(s, r) ((r).states[s].constraint)
  469.  
  470. /* ACCEPTS_IN_CONTEXT returns true if the given state accepts in the
  471.    specified context. */
  472. #define ACCEPTS_IN_CONTEXT(prevn, currn, prevl, currl, state, reg) \
  473.   _SUCCEEDS_IN_CONTEXT((reg).states[state].constraint,           \
  474.                prevn, currn, prevl, currl)
  475.  
  476. /* FIRST_MATCHING_REGEXP returns the index number of the first of parallel
  477.    regexps that a given state could accept.  Parallel regexps are numbered
  478.    starting at 1. */
  479. #define FIRST_MATCHING_REGEXP(state, reg) (-(reg).states[state].first_end)
  480.  
  481. /* Entry points. */
  482.  
  483. #ifdef __STDC__
  484.  
  485. /* Regsyntax() takes two arguments; the first sets the syntax bits described
  486.    earlier in this file, and the second sets the case-folding flag. */
  487. extern void regsyntax(long, int);
  488.  
  489. /* Compile the given string of the given length into the given struct regexp.
  490.    Final argument is a flag specifying whether to build a searching or an
  491.    exact matcher. */
  492. extern void regcompile(const char *, size_t, struct regexp *, int);
  493.  
  494. /* Execute the given struct regexp on the buffer of characters.  The
  495.    first char * points to the beginning, and the second points to the
  496.    first character after the end of the buffer, which must be a writable
  497.    place so a sentinel end-of-buffer marker can be stored there.  The
  498.    second-to-last argument is a flag telling whether to allow newlines to
  499.    be part of a string matching the regexp.  The next-to-last argument,
  500.    if non-NULL, points to a place to increment every time we see a
  501.    newline.  The final argument, if non-NULL, points to a flag that will
  502.    be set if further examination by a backtracking matcher is needed in
  503.    order to verify backreferencing; otherwise the flag will be cleared.
  504.    Returns NULL if no match is found, or a pointer to the first
  505.    character after the first & shortest matching string in the buffer. */
  506. extern char *regexecute(struct regexp *, char *, char *, int, int *, int *);
  507.  
  508. /* Free the storage held by the components of a struct regexp. */
  509. extern void reg_free(struct regexp *);
  510.  
  511. /* Entry points for people who know what they're doing. */
  512.  
  513. /* Initialize the components of a struct regexp. */
  514. extern void reginit(struct regexp *);
  515.  
  516. /* Incrementally parse a string of given length into a struct regexp. */
  517. extern void regparse(const char *, size_t, struct regexp *);
  518.  
  519. /* Analyze a parsed regexp; second argument tells whether to build a searching
  520.    or an exact matcher. */
  521. extern void reganalyze(struct regexp *, int);
  522.  
  523. /* Compute, for each possible character, the transitions out of a given
  524.    state, storing them in an array of integers. */
  525. extern void regstate(int, struct regexp *, int []);
  526.  
  527. /* Error handling. */
  528.  
  529. /* Regerror() is called by the regexp routines whenever an error occurs.  It
  530.    takes a single argument, a NUL-terminated string describing the error.
  531.    The default reg_error() prints the error message to stderr and exits.
  532.    The user can provide a different reg_free() if so desired. */
  533. extern void reg_error(const char *);
  534.  
  535. #else /* ! __STDC__ */
  536. extern void regsyntax(), regcompile(), reg_free(), reginit(), regparse();
  537. extern void reganalyze(), regstate(), reg_error();
  538. extern char *regexecute();
  539. #endif
  540.